﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace UrPortCommunicate
{
    public class UrClient30001
    {
        Socket clientSocket;
        public bool Open(string ip,int port)
        {
            bool result;
            if(clientSocket!=null)
            {
                clientSocket.Close();
            }
            clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //服务端链接ip与端口号
            clientSocket.Connect(new IPEndPoint(IPAddress.Parse(ip), port));
            return true;
        }

        public bool Close()
        {
            if (clientSocket == null) return true;
            clientSocket.Close();
            return true;
        }

        public void SendUrScript(string str)
        {
            clientSocket.Send(Encoding.UTF8.GetBytes(str));
        }

    }
}
